//
//  HJTeasingVC.m
//  project
//
//  Created by jc on 2019/5/6.
//  Copyright © 2019 健健. All rights reserved.
//

#import "HJTeasingVC.h"
#import "HJSettingVC.h"
#import "HJTeasingDetailVC.h"

@interface HJTeasingVC ()
@property (nonatomic,strong) NSArray <HJTeasingModel *> * titleArray;
@end
static NSString *const identifier = @"TeasingCell";
@implementation HJTeasingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navTitle = @"吐个槽";
    [self loadNetworkData];
}
-(void)configTableView {
    self.needHeaderRefresh = YES;
    self.tableViewStyle = UITableViewStylePlain;
    [super configTableView];
    self.tableView.tableHeaderView = [self tableViewHeaderVew];
    self.tableView.tableHeaderView.height = 46;
    self.tableView.rowHeight = 48;
}

-(NSArray <HJTeasingModel *> *)titleArray {
    if (!_titleArray) {
        _titleArray = [NSArray array];
    }
    return _titleArray;
}
-(void)loadNetworkData {
    NSString * url = [Api stringByAppendingString:TypeInfosApi];
    [HJHttpTool get:url params:nil success:^(HJResponeds *result) {
        self.titleArray = [NSArray yy_modelArrayWithClass:[HJTeasingModel class] json:result.data];
        [self.tableView endRefresh];
        [self.tableView reloadData];
    } failure:^(id result) {
        [self showErrorHUDWithError:result];
        [self.tableView endRefresh];
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HJSettingCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell) {
        cell = [[HJSettingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    [cell loadData:self.titleArray[indexPath.row].name];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    HJTeasingDetailVC * teasingDetailVC = [HJTeasingDetailVC new];
    teasingDetailVC.teasingModel = self.titleArray[indexPath.row];
    [self.navigationController pushViewController:teasingDetailVC animated:YES];
}

-(UIView *)tableViewHeaderVew {
    UILabel * title =[UILabel new];
    title.text= @"请选择反馈问题的类型";
    title.textAlignment = NSTextAlignmentCenter;
    title.backgroundColor = [UIColor clearColor];
    title.textColor = [UIColor colorWithHex:0x999999];
    title.font = [UIFont systemFontOFSize13];
    title.frame = CGRectMake(0, 0, SCREEN_WIDTH, 46);
    
    return title;
}

@end


@implementation HJTeasingModel

- (NSString *)description {
    return [self yy_modelDescription];
}

@end
